﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Chowpoo.Sql;

namespace CourseSystem.Core.Entities
{
    [Table(Name = "Question")]
    public class QuestionInfo : IDetach
    {
        public QuestionInfo()
        {
            Detach();
        }
        #region Model
        private int _id;
        private int _questionContentId = 0;
        private DateTime _questiontime = DateTime.Now;
        private int _askerid = 0;
        private string _askername = "";
        private int _answerContentId = 0;
        private DateTime _answertime = DateTime.Now;
        private int _answerid = 0;
        private string _answername = "";
        private bool _iscommon = false;
        private bool _isanswered = false;
        private int _hits = 0;

        private EntityRef<StudentInfo> _studentInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_studentInfo", ThisKey = "AskerId", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public StudentInfo StudentInfo
        {
            get { return _studentInfo.Entity; }
            set { _studentInfo.Entity = value; }
        }

        private EntityRef<CommonContentInfo> _answerContentInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_answerContentInfo", ThisKey = "AnswerContentId", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public CommonContentInfo AnswerContentInfo
        {
            get { return _answerContentInfo.Entity; }
            set { _answerContentInfo.Entity = value; }
        }

        private EntityRef<CommonContentInfo> _questionContentInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_questionContentInfo", ThisKey = "QuestionContentId", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public CommonContentInfo QuestionContentInfo
        {
            get { return _questionContentInfo.Entity; }
            set { _questionContentInfo.Entity = value; }
        }


        /// <summary>
        /// 
        /// </summary>
        [Column(IsDbGenerated = true, IsPrimaryKey = true, IsVersion = true)]
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("提问问题")]
        [Required(ErrorMessage = "必须填写")]
        public int QuestionContentId
        {
            set { _questionContentId = value; }
            get { return _questionContentId; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public DateTime QuestionTime
        {
            set { _questiontime = value; }
            get { return _questiontime; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int AskerId
        {
            set { _askerid = value; }
            get { return _askerid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public string AskerName
        {
            set { _askername = value; }
            get { return _askername; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("回复")]
        public int AnswerContentId
        {
            set { _answerContentId = value; }
            get { return _answerContentId; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public DateTime AnswerTime
        {
            set { _answertime = value; }
            get { return _answertime; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int AnswerId
        {
            set { _answerid = value; }
            get { return _answerid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public string AnswerName
        {
            set { _answername = value; }
            get { return _answername; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("是否常见问题")]
        public bool IsCommon
        {
            set { _iscommon = value; }
            get { return _iscommon; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public bool IsAnswered
        {
            set { _isanswered = value; }
            get { return _isanswered; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int Hits
        {
            set { _hits = value; }
            get { return _hits; }
        }
        #endregion Model

        public void Detach()
        {
            this._studentInfo = default(EntityRef<StudentInfo>);
            this._answerContentInfo = default(EntityRef<CommonContentInfo>);
            this._questionContentInfo = default(EntityRef<CommonContentInfo>);
        }
    }
}
